﻿using System; 
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Matrix.Common.DBUtility;
using Matrix.MaKaYunShang.Model;

namespace Matrix.MaKaYunShang.DAL
{
	public partial class McPendingMessagesDAL : BaseDAL<McPendingMessagesDAL>
	{
		#region 默认方法
		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(McPendingMessages model)
		{
			var strSql=new StringBuilder();
			strSql.Append("insert into McPendingMessages(");			
            strSql.Append("MsgId,IsSendToAll,IsSendToGroup,IsSendToPrivate,ReceiveAccountId,IsProcessed,Created,Updated,ReceiveMobileNo,ReceiveEmail,ProcessStatus,Disabled,IsDelete");
			strSql.Append(") values (");
            strSql.Append("@MsgId,@IsSendToAll,@IsSendToGroup,@IsSendToPrivate,@ReceiveAccountId,@IsProcessed,@Created,@Updated,@ReceiveMobileNo,@ReceiveEmail,@ProcessStatus,@Disabled,@IsDelete");            
            strSql.Append(") ");            
            strSql.Append(";select @@IDENTITY");		
			SqlParameter[] parameters = {
			            new SqlParameter("@MsgId", SqlDbType.Int,4) ,            
                        new SqlParameter("@IsSendToAll", SqlDbType.Bit,1) ,            
                        new SqlParameter("@IsSendToGroup", SqlDbType.Bit,1) ,            
                        new SqlParameter("@IsSendToPrivate", SqlDbType.Bit,1) ,            
                        new SqlParameter("@ReceiveAccountId", SqlDbType.Int,4) ,            
                        new SqlParameter("@IsProcessed", SqlDbType.Bit,1) ,            
                        new SqlParameter("@Created", SqlDbType.DateTime) ,            
                        new SqlParameter("@Updated", SqlDbType.DateTime) ,            
                        new SqlParameter("@ReceiveMobileNo", SqlDbType.NVarChar,20) ,            
                        new SqlParameter("@ReceiveEmail", SqlDbType.NVarChar,100) ,            
                        new SqlParameter("@ProcessStatus", SqlDbType.NVarChar,50) ,            
                        new SqlParameter("@Disabled", SqlDbType.Bit,1) ,            
                        new SqlParameter("@IsDelete", SqlDbType.Bit,1)             
              
            };
			            
            parameters[0].Value = model.MsgId;                        
            parameters[1].Value = model.IsSendToAll;                        
            parameters[2].Value = model.IsSendToGroup;                        
            parameters[3].Value = model.IsSendToPrivate;                        
            parameters[4].Value = model.ReceiveAccountId;                        
            parameters[5].Value = model.IsProcessed;                        
            parameters[6].Value = model.Created;                        
            parameters[7].Value = model.Updated;                        
            parameters[8].Value = model.ReceiveMobileNo;                        
            parameters[9].Value = model.ReceiveEmail;                        
            parameters[10].Value = model.ProcessStatus;                        
            parameters[11].Value = model.Disabled;                        
            parameters[12].Value = model.IsDelete;            			var obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);			
			return obj == null ? 0 : Convert.ToInt32(obj);
		}
				
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(McPendingMessages model)
		{
			var strSql=new StringBuilder();
			strSql.Append("update McPendingMessages set ");
			                                                
            strSql.Append(" MsgId = @MsgId , ");                                    
            strSql.Append(" IsSendToAll = @IsSendToAll , ");                                    
            strSql.Append(" IsSendToGroup = @IsSendToGroup , ");                                    
            strSql.Append(" IsSendToPrivate = @IsSendToPrivate , ");                                    
            strSql.Append(" ReceiveAccountId = @ReceiveAccountId , ");                                    
            strSql.Append(" IsProcessed = @IsProcessed , ");                                    
            strSql.Append(" Created = @Created , ");                                    
            strSql.Append(" Updated = @Updated , ");                                    
            strSql.Append(" ReceiveMobileNo = @ReceiveMobileNo , ");                                    
            strSql.Append(" ReceiveEmail = @ReceiveEmail , ");                                    
            strSql.Append(" ProcessStatus = @ProcessStatus , ");                                    
            strSql.Append(" Disabled = @Disabled , ");                                    
            strSql.Append(" IsDelete = @IsDelete  ");            			
			strSql.Append(" where Id=@Id ");
						
			SqlParameter[] parameters = {
			            new SqlParameter("@Id", SqlDbType.Int,4) ,            
                        new SqlParameter("@MsgId", SqlDbType.Int,4) ,            
                        new SqlParameter("@IsSendToAll", SqlDbType.Bit,1) ,            
                        new SqlParameter("@IsSendToGroup", SqlDbType.Bit,1) ,            
                        new SqlParameter("@IsSendToPrivate", SqlDbType.Bit,1) ,            
                        new SqlParameter("@ReceiveAccountId", SqlDbType.Int,4) ,            
                        new SqlParameter("@IsProcessed", SqlDbType.Bit,1) ,            
                        new SqlParameter("@Created", SqlDbType.DateTime) ,            
                        new SqlParameter("@Updated", SqlDbType.DateTime) ,            
                        new SqlParameter("@ReceiveMobileNo", SqlDbType.NVarChar,20) ,            
                        new SqlParameter("@ReceiveEmail", SqlDbType.NVarChar,100) ,            
                        new SqlParameter("@ProcessStatus", SqlDbType.NVarChar,50) ,            
                        new SqlParameter("@Disabled", SqlDbType.Bit,1) ,            
                        new SqlParameter("@IsDelete", SqlDbType.Bit,1)             
              
            };
						            
            parameters[0].Value = model.Id;                        
            parameters[1].Value = model.MsgId;                        
            parameters[2].Value = model.IsSendToAll;                        
            parameters[3].Value = model.IsSendToGroup;                        
            parameters[4].Value = model.IsSendToPrivate;                        
            parameters[5].Value = model.ReceiveAccountId;                        
            parameters[6].Value = model.IsProcessed;                        
            parameters[7].Value = model.Created;                        
            parameters[8].Value = model.Updated;                        
            parameters[9].Value = model.ReceiveMobileNo;                        
            parameters[10].Value = model.ReceiveEmail;                        
            parameters[11].Value = model.ProcessStatus;                        
            parameters[12].Value = model.Disabled;                        
            parameters[13].Value = model.IsDelete;                        return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0;
		}
				
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int Id)
		{
			var strSql=new StringBuilder();
			strSql.Append("update McPendingMessages set IsDelete=1 ");
			strSql.Append(" where Id=@Id");
						SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
			parameters[0].Value = Id;

			return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0;
		}
		
				/// <summary>
		/// 批量删除一批数据
		/// </summary>
		public bool DeleteList(string Idlist )
		{
			var strSql=new StringBuilder();
			strSql.Append("update McPendingMessages set IsDelete=1 ");
			strSql.Append(" where Id in ("+Idlist + ")  ");
			return DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;
		}
						
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DataSet GetModel(int Id)
		{
			var strSql=new StringBuilder();
			strSql.Append("select Id, MsgId, IsSendToAll, IsSendToGroup, IsSendToPrivate, ReceiveAccountId, IsProcessed, Created, Updated, ReceiveMobileNo, ReceiveEmail, ProcessStatus, Disabled, IsDelete  ");			
			strSql.Append("  from McPendingMessages ");
			strSql.Append(" where Id=@Id  and IsDelete=0");
						SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
			parameters[0].Value = Id;
			
			var ds = DbHelperSQL.Query(strSql.ToString(),parameters);			
			return ds.Tables[0].Rows.Count>0 ? ds : null;
		}
				
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			var strSql=new StringBuilder();
			strSql.Append("select * ");
			strSql.Append(" FROM McPendingMessages where IsDelete=0 ");
			if(!string.IsNullOrEmpty(strWhere))
			{
				strSql.Append(" and "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}		
		#endregion
		
		#region 扩展方法
		#endregion
	}
}
